package lab02.test06;

public class Triangle {
    private double edge1;
    private double edge2;
    private double edge3;
    double area;
    double length;
    boolean judge;

    public void setEdge1(double edge1) {
        this.edge1 = edge1;
    }

    public double getEdge1() {
        return edge1;
    }

    public void setEdge2(double edge2) {
        this.edge2 = edge2;
    }

    public double getEdge2() {
        return edge2;
    }

    public void setEdge3(double edge3) {
        this.edge3 = edge3;
    }

    public double getEdge3() {
        return edge3;
    }

    public void triangle(double edge1, double edge2, double edge3) {
        if (getEdge1() + getEdge2() > getEdge3() && getEdge1() + getEdge3() > getEdge2() && getEdge2() + getEdge3() > getEdge1()) {
            judge = true;
        } else judge = false;
    }

    //计算三角形周长
    public double length() {
        if (judge = true) {
            length = getEdge1() + getEdge2() + getEdge3();
            System.out.println("该三角形周长为：" + length);
            return length;
        } else {
            System.out.println("这组数据不能构成三角形，不能计算周长");
            return 0;
        }
    }

    //计算三角形面积
    public double area() {
        if (judge) {
            double p = (getEdge1() + getEdge2() + getEdge3());
            area = Math.sqrt(p * (p - getEdge1()) * (p - getEdge2()) * (p - getEdge3()));
            System.out.println("三角形" + area);
            return area;
        } else {
            System.out.println("这组数据不能构成三角形，不能计算面积");
            return 0;
        }
    }
}
